home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2009 December / maximum-cd-2009-12.iso / DiscContents / gimp-2.7.0-i686-setup.exe / {app} / share / gimp / 2.0 / scripts / add-bevel.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2009-08-19  |  6.8 KB  |  198 lines

  1. ; GIMP - The GNU Image Manipulation Program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; add-bevel.scm version 1.04
  5. ; Time-stamp: <2004-02-09 17:07:06 simon>
  6. ;
  7. ; This program is free software: you can redistribute it and/or modify
  8. ; it under the terms of the GNU General Public License as published by
  9. ; the Free Software Foundation; either version 3 of the License, or
  10. ; (at your option) any later version.
  11. ;
  12. ; This program is distributed in the hope that it will be useful,
  13. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. ; GNU General Public License for more details.
  16. ;
  17. ; You should have received a copy of the GNU General Public License
  18. ; along with this program.  If not, see <http://www.gnu.org/licenses/>.
  19. ;
  20. ; Copyright (C) 1997 Andrew Donkin  (ard@cs.waikato.ac.nz)
  21. ; Contains code from add-shadow.scm by Sven Neumann
  22. ; (neumanns@uni-duesseldorf.de) (thanks Sven).
  23. ;
  24. ; Adds a bevel to an image.  See http://www.cs.waikato.ac.nz/~ard/gimp/
  25. ;
  26. ; If there is a selection, it is bevelled.
  27. ; Otherwise if there is an alpha channel, the selection is taken from it
  28. ; and bevelled.
  29. ; Otherwise the part of the layer inside the image boundries is bevelled.
  30. ;
  31. ; The selection is set on exit, so Select->Invert then Edit->Clear will
  32. ; leave a cut-out.  Then use Sven's add-shadow for that
  33. ; floating-bumpmapped-texture cliche.
  34.  
  35. ;
  36. ; 1.01: now works on offset layers.
  37. ; 1.02: has crop-pixel-border option to trim one pixel off each edge of the
  38. ;       bevelled image.  Bumpmapping leaves edge pixels unchanged, which
  39. ;       looks bad.  Oddly, this is not apparant in GIMP - you have to
  40. ;       save the image and load it into another viewer.  First noticed in
  41. ;       Nutscrape.
  42. ;       Changed path (removed "filters/").
  43. ; 1.03: adds one-pixel border before bumpmapping, and removes it after.
  44. ;       Got rid of the crop-pixel-border option (no longer reqd).
  45. ; 1.04: Fixed undo handling, ensure that bumpmap is big enough,
  46. ;       (instead of resizing the image). Removed references to outdated
  47. ;       bumpmap plugin.     (Simon)
  48. ; 1.05  When there is no selection, bevel the whole layer instead of the
  49. ;       whole image (which was broken in the first place).
  50. ;       Also fixed some bugs with setting the selection when there is no
  51. ;       initial selection.     (Barak Itkin)
  52. ;
  53.  
  54. (define (script-fu-add-bevel img
  55.                              drawable
  56.                              thickness
  57.                              work-on-copy
  58.                              keep-bump-layer)
  59.  
  60.   (let* (
  61.         (index 1)
  62.         (greyness 0)
  63.         (thickness (abs thickness))
  64.         (type (car (gimp-drawable-type-with-alpha drawable)))
  65.         (image (if (= work-on-copy TRUE) (car (gimp-image-duplicate img)) img))
  66.         (pic-layer (car (gimp-image-get-active-drawable image)))
  67.         (offsets (gimp-drawable-offsets pic-layer))
  68.         (width (car (gimp-drawable-width pic-layer)))
  69.         (height (car (gimp-drawable-height pic-layer)))
  70.  
  71.         ; Bumpmap has a one pixel border on each side
  72.         (bump-layer (car (gimp-layer-new image
  73.                                          (+ width 2)
  74.                                          (+ height 2)
  75.                                          RGB-IMAGE
  76.                                          "Bumpmap"
  77.                                          100
  78.                                          NORMAL-MODE)))
  79.  
  80.         (selection-exists (car (gimp-selection-bounds image)))
  81.         (selection 0)
  82.         )
  83.  
  84.     (gimp-context-push)
  85.  
  86.     ; disable undo on copy, start group otherwise
  87.     (if (= work-on-copy TRUE)
  88.       (gimp-image-undo-disable image)
  89.       (gimp-image-undo-group-start image)
  90.     )
  91.  
  92.     (gimp-image-add-layer image bump-layer 1)
  93.  
  94.     ; If the layer we're bevelling is offset from the image's origin, we
  95.     ; have to do the same to the bumpmap
  96.     (gimp-layer-set-offsets bump-layer (- (car offsets) 1)
  97.                                        (- (cadr offsets) 1))
  98.  
  99.     ;------------------------------------------------------------
  100.     ;
  101.     ; Set the selection to the area we want to bevel.
  102.     ;
  103.     (if (= selection-exists 0)
  104.         (gimp-selection-layer-alpha pic-layer)
  105.     )
  106.  
  107.     ; Store it for later.
  108.     (set! selection (car (gimp-selection-save image)))
  109.     ; Try to lose the jaggies
  110.     (gimp-selection-feather image 2)
  111.  
  112.     ;------------------------------------------------------------
  113.     ;
  114.     ; Initialise our bumpmap
  115.     ;
  116.     (gimp-context-set-background '(0 0 0))
  117.     (gimp-drawable-fill bump-layer BACKGROUND-FILL)
  118.  
  119.     (while (< index thickness)
  120.            (set! greyness (/ (* index 255) thickness))
  121.            (gimp-context-set-background (list greyness greyness greyness))
  122.            ;(gimp-selection-feather image 1) ;Stop the slopey jaggies?
  123.            (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
  124.                                   100 0 FALSE 0 0)
  125.            (gimp-selection-shrink image 1)
  126.            (set! index (+ index 1))
  127.     )
  128.     ; Now the white interior
  129.     (gimp-context-set-background '(255 255 255))
  130.     (gimp-edit-bucket-fill bump-layer BG-BUCKET-FILL NORMAL-MODE
  131.                            100 0 FALSE 0 0)
  132.  
  133.     ;------------------------------------------------------------
  134.     ;
  135.     ; Do the bump.
  136.     ;
  137.     (gimp-selection-none image)
  138.  
  139.     ; To further lessen jaggies?
  140.     ;(plug-in-gauss-rle RUN-NONINTERACTIVE image bump-layer thickness TRUE TRUE)
  141.  
  142.  
  143.     ;
  144.     ; BUMPMAP INVOCATION:
  145.     ;
  146.     (plug-in-bump-map RUN-NONINTERACTIVE image pic-layer bump-layer 125 45 3 0 0 0 0 TRUE FALSE 1)
  147.  
  148.     ;------------------------------------------------------------
  149.     ;
  150.     ; Restore things
  151.     ;
  152.     (if (= selection-exists 0)
  153.         (gimp-selection-none image)        ; No selection to start with
  154.         (gimp-selection-load selection)
  155.     )
  156.     ; If they started with a selection, they can Select->Invert then
  157.     ; Edit->Clear for a cutout.
  158.  
  159.     ; clean up
  160.     (gimp-image-remove-channel image selection)
  161.     (if (= keep-bump-layer TRUE)
  162.         (gimp-drawable-set-visible bump-layer 0)
  163.         (gimp-image-remove-layer image bump-layer)
  164.     )
  165.  
  166.     (gimp-image-set-active-layer image pic-layer)
  167.  
  168.     ; enable undo / end undo group
  169.     (if (= work-on-copy TRUE)
  170.       (begin
  171.         (gimp-display-new image)
  172.         (gimp-image-undo-enable image)
  173.       )
  174.       (gimp-image-undo-group-end image)
  175.     )
  176.  
  177.     (gimp-displays-flush)
  178.  
  179.     (gimp-context-pop)
  180.   )
  181. )
  182.  
  183. (script-fu-register "script-fu-add-bevel"
  184.   _"Add B_evel..."
  185.   _"Add a beveled border to an image"
  186.   "Andrew Donkin <ard@cs.waikato.ac.nz>"
  187.   "Andrew Donkin"
  188.   "1997/11/06"
  189.   "RGB*"
  190.   SF-IMAGE       "Image"           0
  191.   SF-DRAWABLE    "Drawable"        0
  192.   SF-ADJUSTMENT _"Thickness"       '(5 0 30 1 2 0 0)
  193.   SF-TOGGLE     _"Work on copy"    TRUE
  194.   SF-TOGGLE     _"Keep bump layer" FALSE
  195. )
  196.  
  197. (script-fu-menu-register "script-fu-add-bevel" "<Image>/Filters/Decor")
  198.